package com.cskaoyan.service;

import com.cskaoyan.bean.MarketFootprint;
import com.cskaoyan.bean.MarketFootprintExample;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.mapper.MarketFootprintMapper;
import com.cskaoyan.util.StringUtil;
import com.cskaoyan.util.TransactionUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.List;

public class FootServiceImpl implements FootService {
    @Override
    public CommonData<MarketFootprint> query(Integer page, Integer limit, String sort, String order, Integer userId, Integer goodsId) {
        MarketFootprintExample example=new MarketFootprintExample();
        MarketFootprintExample.Criteria criteria = example.createCriteria();

        if (userId != null) {
            criteria.andUserIdEqualTo(userId);
        }
        if (goodsId != null) {
            criteria.andGoodsIdEqualTo(goodsId);
        }

        criteria.andDeletedEqualTo(false);

        if (!StringUtil.isEmpty(sort) && !StringUtil.isEmpty(order)) {
            example.setOrderByClause(sort + " " + order);
        }
        PageHelper.startPage(page, limit);


        MarketFootprintMapper marketFootprintMapper = TransactionUtil.getMapper(MarketFootprintMapper.class);
        PageHelper.startPage(page, limit);
        List<MarketFootprint> marketFootprints= marketFootprintMapper.selectByExample(example);
        return CommonData.data(new PageInfo(marketFootprints));
    }
}
